package cn.xaut.查找表;

import java.util.HashMap;
import java.util.Map;

public class demo454 {

    public int fourSumCount(int[] A, int[] B, int[] C, int[] D) {

        Map<Integer, Integer> map = new HashMap<>();
        for (int a : A) 
            for (int b : B)
                map.put(a + b, map.getOrDefault(a + b, 0) + 1);
            
        int count = 0;
        for (int c : C)
            for (int d : D)
                if (map.containsKey(-c-d))
                    count += map.get(-c-d);
            
        return count;
    }

    public static void main(String[] args) {
        
        System.out.println(new demo454().fourSumCount(new int[]{1, 2}, new int[]{-2, -1}, new int[]{-1, 2}, new int[]{0, 2}));//2
    }
}
